﻿using System;
using Spring.Context;
using Spring.Context.Support;
using Spring.Validation;

namespace SpringSeries.Core.Validation {
    class Program {
        static void Main(string[] args) {
            IApplicationContext _context = ContextRegistry.GetContext();

            Person _p01 = new Person(1);
            _p01.FirstName = "Matteo";
            _p01.LastName = "Baglini";
            _p01.DateOfBirth = new DateTime(1982, 11, 8);

            Person _p02 = new Person(2);
            _p02.LastName = "Baglini";
            _p02.DateOfBirth = new DateTime(1982, 11, 8);

            Person _p03 = new Person(3);
            _p03.FirstName = "Matteo";
            _p03.LastName = "Baglini";

            Person _p04 = new Person(4);
            _p04.FirstName = "Matteo";
            _p04.LastName = "Baglini";
            _p04.DateOfBirth = new DateTime(1982, 11, 8);
            _p04.AddressInfo.Address = "Via dei Sassi Sgonfi";

            Person _p05 = new Person(5);
            _p05.FirstName = "Matteo";
            _p05.LastName = "Baglini";
            _p05.DateOfBirth = new DateTime(1982, 11, 8);
            _p05.AddressInfo.Address = "Via dei Sassi Sgonfi";
            _p05.AddressInfo.City = "Livorno";
            _p05.AddressInfo.PostalCode = "57100";

            Person _p06 = new Person(6);
            _p06.FirstName = "1234567890";
            _p06.LastName = "Baglini";
            _p06.DateOfBirth = new DateTime(1982, 11, 8);
            _p06.AddressInfo.Address = "Via dei Sassi Sgonfi";
            _p06.AddressInfo.City = "Livorno";
            _p06.AddressInfo.PostalCode = "57100";

            IValidator _validator = (IValidator)_context.GetObject("PersonValidator");

            Console.WriteLine(_p01.ToString());
            Console.WriteLine("Is Valid? {0}", _validator.Validate(_p01,null));
            Console.WriteLine();
            Console.WriteLine(_p02.ToString());
            Console.WriteLine("Is Valid? {0}", _validator.Validate(_p02, null));
            Console.WriteLine();
            Console.WriteLine(_p03.ToString());
            Console.WriteLine("Is Valid? {0}", _validator.Validate(_p03, null));
            Console.WriteLine();
            Console.WriteLine(_p04.ToString());
            Console.WriteLine("Is Valid? {0}", _validator.Validate(_p04, null));
            Console.WriteLine();
            Console.WriteLine(_p05.ToString());
            Console.WriteLine("Is Valid? {0}", _validator.Validate(_p05, null));
            Console.WriteLine();
            Console.WriteLine(_p06.ToString());
            Console.WriteLine("Is Valid? {0}", _validator.Validate(_p06, null));

            Console.Read();
        }
    }
}
